<?php
namespace Arathi\Weibo;

class Status
{
    public $id;
    public $uid;
    public $createdAt;
    public $content;
    
    public function __construct($msgBody)
    {
        $this->id = $msgBody->id;
        $this->uid = $msgBody->user->id;
        $this->content = $msgBody->text;

        $timeFormat = "D M d H:i:s O Y";
        $dateobj = date_create_from_format($timeFormat, $msgBody->created_at);

        // $timeFormat = "%a %b %d %T %z %Y";  // Wed Jan 04 14:41:06 +0800 2017
        $this->createdAt = $dateobj;
    }

    public function toString()
    {
        $formattedTime = $this->createdAt->format(DATE_ATOM);

        $info = "$this->id : $this->uid : $formattedTime : $this->content";
        return $info;
    }

    public function toFillableArray()
    {
        return [
            'status_id' => $this->id,
            'user_id' => $this->uid,
            'post_time' => $this->createdAt,
            'content' => $this->content
        ];
    }
}
